package com.ruoyi.sl.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.sl.domain.SlFixedSalary;
import com.ruoyi.sl.service.ISlFixedSalaryService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 固定薪水Controller
 * 
 * @author admin
 * @date 2024-06-10
 */
@RestController
@RequestMapping("/sl/salary")
public class SlFixedSalaryController extends BaseController
{
    @Autowired
    private ISlFixedSalaryService slFixedSalaryService;

    /**
     * 查询固定薪水列表
     */
    @PreAuthorize("@ss.hasPermi('sl:salary:list')")
    @GetMapping("/list")
    public TableDataInfo list(SlFixedSalary slFixedSalary)
    {
        startPage();
        List<SlFixedSalary> list = slFixedSalaryService.selectSlFixedSalaryList(slFixedSalary);
        return getDataTable(list);
    }

    /**
     * 导出固定薪水列表
     */
    @PreAuthorize("@ss.hasPermi('sl:salary:export')")
    @Log(title = "固定薪水", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SlFixedSalary slFixedSalary)
    {
        List<SlFixedSalary> list = slFixedSalaryService.selectSlFixedSalaryList(slFixedSalary);
        ExcelUtil<SlFixedSalary> util = new ExcelUtil<SlFixedSalary>(SlFixedSalary.class);
        util.exportExcel(response, list, "固定薪水数据");
    }

    /**
     * 获取固定薪水详细信息
     */
    @PreAuthorize("@ss.hasPermi('sl:salary:query')")
    @GetMapping(value = "/{fsId}")
    public AjaxResult getInfo(@PathVariable("fsId") Long fsId)
    {
        return success(slFixedSalaryService.selectSlFixedSalaryByFsId(fsId));
    }

    /**
     * 新增固定薪水
     */
    @PreAuthorize("@ss.hasPermi('sl:salary:add')")
    @Log(title = "固定薪水", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SlFixedSalary slFixedSalary)
    {
        slFixedSalary.setCreateBy(getUsername());
        return toAjax(slFixedSalaryService.insertSlFixedSalary(slFixedSalary));
    }

    /**
     * 修改固定薪水
     */
    @PreAuthorize("@ss.hasPermi('sl:salary:edit')")
    @Log(title = "固定薪水", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SlFixedSalary slFixedSalary)
    {
        slFixedSalary.setUpdateBy(getUsername());
        return toAjax(slFixedSalaryService.updateSlFixedSalary(slFixedSalary));
    }

    /**
     * 删除固定薪水
     */
    @PreAuthorize("@ss.hasPermi('sl:salary:remove')")
    @Log(title = "固定薪水", businessType = BusinessType.DELETE)
	@DeleteMapping("/{fsIds}")
    public AjaxResult remove(@PathVariable Long[] fsIds)
    {
        return toAjax(slFixedSalaryService.deleteSlFixedSalaryByFsIds(fsIds));
    }
}
